﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameEngine.Scenes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using GuiLibrary;
using GuiLibrary.layouts;
using GuiLibrary.Components;


namespace GuiLibrary
{
    public abstract class Gui : Scene, IOnElementSelected
    {

        public Panel basePanel;

        public Gui(Panel basePanel)
            : base(false, false)
        {
            this.basePanel = basePanel;
        }
        
        public Gui()
            :this(null)
        {
            
        }

        public override void draw(SpriteBatch sb)
        {
            sb.Begin();
            if(background!=null)background.draw(sb);
            basePanel.draw(sb);
            basePanel.layout.draw(sb);
            sb.End();
        }

        public override void update(GameTime gameTime)
        {
            basePanel.layout.update(gameTime.ElapsedGameTime.Milliseconds);
            base.update(gameTime);
        }

        public override void handleInput()
        {
            InputManager im = InputManager.getInstance();
            Layout.Cursor cursor = im.isNewKeyPressed(Keys.Down)?
                Layout.Cursor.DOWN:
                im.isNewKeyPressed(Keys.Up) ?
                Layout.Cursor.UP:
                im.isNewKeyPressed(Keys.Right) ?
                Layout.Cursor.RIGHT:
                im.isNewKeyPressed(Keys.Left) ?
                Layout.Cursor.LEFT:
                im.isNewKeyPressed(Keys.Enter) ?
                Layout.Cursor.ENTER:
                im.isNewKeyPressed(Keys.Escape) ?
                Layout.Cursor.CANCEL:
                Layout.Cursor.NONE;
            basePanel.moveCursor(cursor);
        }

        

        #region IOnElementSelected Members
        
        public abstract void onSelectedElement(Element e);

        #endregion
    }
}
